
package com.bangcommunity.bbframe.dynconfig;

import com.bangcommunity.bbframe.common.utils.io.PropertiesUtil;
import com.bangcommunity.bbframe.dynconfig.parser.PropertyValueParserUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Properties;

/**
 * Created by tanghc
 */
public class CommonDynConfig {

    public static final Logger logger = LoggerFactory.getLogger(CommonDynConfig.class);
    public static final String config_group = "common";
    public static final String config_data_id = "dynconfig";
    private static Properties properties = null;

    private CommonDynConfig() {
    }

    static {
        DynConfigRegister.getInstance().buildOnce(config_group, config_data_id, new IDynConfigProcessor() {

            @Override
            public void procesConfig(String config) {

                properties = PropertiesUtil.loadFromString(config);
            }
        });
    }

    public static String getValue(String key) {
        return PropertyValueParserUtil.getValue(properties, key, null);
    }

    public static String getValue(String key, String defaultValue) {
        return PropertyValueParserUtil.getValue(properties, key, defaultValue);

    }
}
